package com.group.yztcedu.playlive.main.home.adapter;

import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.group.yztcedu.playlive.R;
import com.group.yztcedu.playlive.bean.HomeHotUsersBean;
import com.group.yztcedu.playlive.main.playvideo.PlayVideoActivity;
import com.group.yztcedu.playlive.utils.RoundImageUtil;

import java.util.List;

public class HotUserAdapter extends BaseAdapter {
    private List<HomeHotUsersBean> mList;
    public HotUserAdapter(List<HomeHotUsersBean> list){
        this.mList = list;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, final ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.home_gridview_item,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else{
           holder = (ViewHolder) view.getTag();
        }
        HomeHotUsersBean homeHotUsersBean = mList.get(i);
        String avatarUrl = homeHotUsersBean.getAvatar();
        final int roomId = homeHotUsersBean.getRoomId();
        String username = homeHotUsersBean.getUsername();
        RoundImageUtil.getRoundImage(viewGroup.getContext(),avatarUrl,holder.photo);
        holder.photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(viewGroup.getContext(),PlayVideoActivity.class);
                intent.putExtra("roomId",roomId+"");
                viewGroup.getContext().startActivity(intent);
            }
        });
        holder.text.setText(username);
        return view;
    }
    class ViewHolder{
        private ImageView photo;
        private TextView text;
        public ViewHolder(View view){
           photo = (ImageView) view.findViewById(R.id.home_hot_iv);
            text = (TextView) view.findViewById(R.id.home_hot_tv);
        }
    }
}
